import unittest

import requests
from parameterized import parameterized

from p2p.api import log
from p2p.api.api_register_login import ApiRegisterLogin
from p2p.api.api_tender import ApiTender
from p2p.util import read_json


class TestTender(unittest.TestCase):
    def setUp(self) -> None:
        self.session=requests.session()
        self.tender=ApiTender(self.session)
        ApiRegisterLogin(self.session).api_login()

    def tearDown(self) -> None:
        self.session.close()


    @parameterized.expand(read_json("tender.json","tender"))
    def test_tender_success(self,amount,expect):
        try:
            r=self.tender.api_tender(amount)
            if amount==100:
                self.assertIn(expect,r.text)
            else:
                self.assertIn(expect, r.text)

        except Exception as e:
            log.error(e)
            raise


